﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlockMain_Api.Models;
using BlockMain_Class;
using Microsoft.AspNetCore.Mvc;

namespace BlockMain_Api.Controllers
{
    public class LoginController : Controller
    {
        public static MongodbHelpers<PeerList> mon = new MongodbHelpers<PeerList>();
        /// <summary>
        /// 处理客户端的登录请求  暂时简单处理下
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Index(string account,string pwd)
        {
            LoginInfo login = new LoginInfo();
            var list = mon.QueryAll();
            var first = list.FirstOrDefault(a => a.Account == account && a.Password == pwd);
            if (first != null)
            {
                return Json(new LoginInfo
                {
                    message = "ok",
                    account = first.Account,
                    Id = first.Id.ToString()
                });
            }
            else
            {
                return Json(new LoginInfo
                {
                    message = "账号或密码错误,请重试!",
                });
            }
        }
    }
}